package com.patrick.open.api.core.exception;

import com.patrick.open.api.core.common.RespCode;
import com.patrick.open.api.core.common.RespData;

/**
 * 基础错误异常
 *
 * @author admin
 */
public class OpenException extends RuntimeException {

  private static final long serialVersionUID = 3655050728585279326L;

  private int code = RespCode.ERROR.getCode();

  public OpenException() {

  }

  public OpenException(String msg) {
    super(msg);
  }

  public OpenException(int code, String msg) {
    super(msg);
    this.code = code;
  }

  public OpenException(int code, String msg, Throwable cause) {
    super(msg, cause);
    this.code = code;
  }

  public int getCode() {
    return code;
  }

  public void setCode(int code) {
    this.code = code;
  }

  /**
   * 转换为应答对象
   *
   * @return
   */
  public RespData toRespData(String msg) {
    return RespData.failed().code(code).msg(msg);
  }

}
